home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacAddict 123
/
MacAddict_123_2006_11.iso
/
Software
/
Productivity
/
iClip lite 2.wdgt
/
js
/
button.js
< prev
next >
Wrap
Text File
|
2006-06-16
|
2KB
|
102 lines
// Copyright © 2006, Inventive. //
// Classes //
function Button(node, directory, animating, frames, anicallback, interval, callback) {
var self = this;
// Events //
addEvent(node, "mousemove", false, function() {
if (!self.hover) {
self.hover = true;
if (self.timer == null)
self.update();
}
});
addEvent(node, "mousedown", false, function(event) {
self.active = true;
if (self.timer == null)
self.update();
buttons.current = self;
event.returnValue = false;
});
addEvent(node, "mouseout", false, function() {
self.hover = false;
if (self.timer == null)
self.update();
});
// User-set variables //
this.node = node;
this.directory = directory;
this.animating = animating;
this.frames = frames;
this.interval = interval;
this.callback = callback;
this.anicallback = anicallback;
// Variables //
this.hover = false;
this.active = false;
this.frame = 1;
this.timer = null;
}
Button.prototype.update = function() {
this.node.src = "media/" + this.directory + "/" + (this.hover ? (this.active ? "active" : "hover") : "normal") + (this.animating ? "/" + this.frame : "") + ".png";
}
Button.prototype.start = function() {
if (this.animating && this.timer == null) {
var self = this;
this.timer = setInterval(function() {
if (self.frame == self.frames)
self.frame = 1;
else
self.frame += 1
if (visible)
self.update();
self.anicallback();
}, this.interval);
}
}
Button.prototype.stop = function() {
if (this.timer != null) {
clearInterval(this.timer);
this.timer = null;
}
}
// Events //
addEvent(window, "mouseup", false, function() {
if (buttons.current != null) {
buttons.current.active = false;
if (buttons.current.hover) {
buttons.current.hover = false;
buttons.current.update();
buttons.current.callback();
}
buttons.current = null;
}
});
// Functions //
function addButton(node, directory, callback) {
buttons.instances[node.id] = new Button(node, directory, false, 0, null, 0, callback);
}
function addAnimatingButton(node, directory, frames, anicallback, interval, callback) {
buttons.instances[node.id] = new Button(node, directory, true, frames, anicallback, interval, callback);
}
// Variables //
var buttons = {instances: new Array(), current: null};